package com.sale.goods.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.goods.domain.dto.GoodsTurnDto;
import com.sale.goods.domain.vo.GoodsInvoiceIntoVo;
import com.sale.goods.domain.vo.GoodsTurnVo;
import com.sale.goods.service.IGoodsTurnService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 转账单
 * @Date 23-07-28
 * @Author hl
 **/

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/turn")
public class GoodsTurnController extends BaseController {

    private final IGoodsTurnService goodsTurnService;

    /**
     * 获取转账单
     */
    //@SaCheckPermission("finance:transfer:list")
    @GetMapping("/list")
    public TableDataInfo<GoodsTurnDto> list(GoodsTurnVo goodsTurnVo, PageQuery pageQuery)
    {
        return goodsTurnService.selectTurnList(goodsTurnVo,pageQuery);
    }

    /**
     * 新增转账单
     */
    //@SaCheckPermission("finance:transfer:add")
    @Log(title = "转账单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody GoodsTurnVo goodsTurnVo) throws Exception {
        return toAjax(goodsTurnService.insertTurn(goodsTurnVo));
    }

    /**
     * 根据编号获取详细信息
     */
    @GetMapping(value = "/{turnId}")
    public R getInfo(@PathVariable long turnId)
    {
        return R.ok(goodsTurnService.selectTurnById(turnId));
    }

    /**
     * 修改转账单
     */
    //@SaCheckPermission("finance:transfer:edit")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody GoodsTurnVo goodsTurnVo) {
        return toAjax(goodsTurnService.updateTurnEdit(goodsTurnVo));
    }

    /**
     * 删除转账单
     */
    //@SaCheckPermission("finance:transfer:remove")
    @Log(title = "转账单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{turnId}")
    public R<Void> remove(@PathVariable("turnId") Long turnId) {
        return toAjax(goodsTurnService.deleteTurnById(turnId));
    }

    /**
     * 提交审核
     */
    //@SaCheckPermission("finance:transfer:subExamine")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @GetMapping("/submitReview/{turnId}")
    public R<Void> submitReview(@PathVariable("turnId") Long turnId) {
        return toAjax(goodsTurnService.submitReview(turnId));
    }

    /**
     * 撤销审核
     */
    //@SaCheckPermission("finance:transfer:revoke")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @GetMapping("/deleteReview/{turnId}")
    public R<Void> deleteReview(@PathVariable("turnId") Long turnId) {
        return toAjax(goodsTurnService.deleteReview(turnId));
    }

    /**
     * 审核单据
     */
    //@SaCheckPermission("finance:transfer:examine")
    @Log(title = "转账单", businessType = BusinessType.UPDATE)
    @PostMapping("/examine")
    public R<Void> examine(@Validated @RequestBody GoodsTurnVo goodsTurnVo) throws Exception {
        return toAjax(goodsTurnService.goodSExamineReview(goodsTurnVo));
    }

}
